package kgame5.kgui.kcomp {
import flash.display.MovieClip;

/**
 * @author kk
 * 布置很多网格的一个界面,很有用的东西，道具，商城界面很多要用到这个组件的！
 * 
 * 这个就不要包含滚动条了，滚动条放到外面做吧
 */
public class SmartTilePane {
	
	private var CC:int;//一行能放多少
	private var TileW:int,TileH:int;//一个格子的长宽
	private var GapX:int,GapY:int;//水平间距和垂直间距
	
	private var aTile:Array;//存放各个mc_tile的
	
	private var Width:int;//整个区域宽度
	
	private var mc:MovieClip;
	
	public function SmartTilePane(mc:MovieClip,Width:int,TileW:int,TileH:int,GapX:int,GapY:int){
		
		this.mc=mc;
		
		this.Width=Width;
		this.TileW=TileW;
		this.TileH=TileH;
		this.GapX=GapX;
		this.GapY=GapY;
		
		CC=Width/(TileW+GapX);
		
		aTile=new Array();
	}
	public function getMC():MovieClip{
		return mc;
	}
	public function addTile(mc_tile:MovieClip){
		var idx:int=aTile.length;
		var row:int=idx/CC;
		var col:int=idx%CC;
		var x:int=(TileW+GapX)*col;
		var y:int=(TileH+GapY)*row;
		
		mc_tile.x=x;
		mc_tile.y=y;
		
		mc.addChild(mc_tile);
		aTile.push(mc_tile);
	}
	public function getHeight():int{
		return int(aTile.length/CC)*(TileH+GapY);
	}
	//清空
	public function clear(){
		for each(var mc_tile:MovieClip in aTile){
			mc.removeChild(mc_tile);
		}
		aTile=new Array();
	}
}//end of class
}
